/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.patpro.DAO;

import com.patpro.entidades.Obras;
import com.patpro.entidades.Tipocontrato;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author EVELIN
 */
public class ObrasDAO {
     
    private EntityManagerFactory emf;
    private EntityManager em;
   public ObrasDAO() {
          this.emf = Persistence.createEntityManagerFactory("sicop-patpro-webPU");
        em=emf.createEntityManager();
    }
    
     public void closeEntityManager(){
    em.close();
    }
      public boolean insertarObra(Obras t){
    boolean b=false;
    
    try{
    em.getTransaction().begin();
    em.persist(t);
    em.getTransaction().commit();
    b=true;
    
    
    }catch(Exception e){
    
    em.getTransaction().rollback();
    }
    return b;
    }

    public List<Tipocontrato> getListaTipoContrato() {
        
        return em.createQuery("select t from Tipocontrato t").getResultList();
     
       }

     public List<Obras> getListaObra(){
    return em.createQuery("select o from Obras o").getResultList();
   

    } 
}
